/**
 * 
 */
package ui.model;

import java.text.DateFormat;
import java.util.*;

import javax.swing.table.AbstractTableModel;

import exceptions.*;

import appControll.AppController;

import model.*;

/**
 * @author Anthares & Hennek
 *
 */
public class SyllabusEtudiantModel extends AbstractTableModel {
	private ArrayList<Commande_etu> content = new ArrayList<Commande_etu>();
	private ArrayList<String> columnNames = new ArrayList<String>();
	private AppController app = new AppController();
	
	public SyllabusEtudiantModel(){
		columnNames.add("Matricule");
		columnNames.add("Nom");
		columnNames.add("Prenom");
		columnNames.add("Syllabus");
		columnNames.add("Auteur");
		columnNames.add("Date de commande");
	}
	public SyllabusEtudiantModel(String etu) throws PasIdentificationException, DatabaseErrorException, InvalidDataException{
		this();
		content = app.rechercheSyllabusEtudiant(etu);
	}
	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getColumnCount()
	 */
	@Override
	public int getColumnCount() {
		return columnNames.size();
	}

	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getRowCount()
	 */
	@Override
	public int getRowCount() {
		return content.size();
	}
	public String getColumnName(int col){
		return columnNames.get(col);
	}

	/* (non-Javadoc)
	 * @see javax.swing.table.TableModel#getValueAt(int, int)
	 */
	@Override
	public Object getValueAt(int row, int col) {
		Commande_etu c = content.get(row);
		DateFormat df = DateFormat.getDateInstance();
		switch(col){
		case 0: return c.getClient().getMatricule();
		case 1: return c.getClient().getNom();
		case 2: return c.getClient().getPrenom();
		case 3: return c.getContenu().get(0).getIntitule();
		case 4: return c.getContenu().get(0).getAuteur().getPrenom()+" "+c.getContenu().get(0).getAuteur().getNom();
		case 5: return df.format(c.getDate_commande().getTime());
		default: return null;
		}
	}
	public Class getColumnClass(int col){
		Class c;
		switch (col) {
		default: c = String.class;
			break;
		}
		return c;
	}
}
